package com.chenzhou.controller;

import com.chenzhou.entity.GoodsTypeEntity;
import com.chenzhou.service.GoodsTypeServie;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping("/goodsType")
public class GoodsTypeController {

    @Autowired
    private GoodsTypeServie servie;

     @RequestMapping("/query_goodsType")
     public String queryAllGoodsType(HttpServletRequest request){
         List<GoodsTypeEntity> list = servie.queryAllGoodsType();
         request.setAttribute("menu","goods_type");
         request.setAttribute("glist",list);
         return "goods_type/show_goodsType";
     }

     @RequestMapping("/queryGoodsTypeOne")
     public String queryGoodsTypeOne(HttpServletRequest request,Integer id){
         GoodsTypeEntity goodsTypeEntity = servie.queryGoodsTypeEntityByID(id);
         request.setAttribute("goodsType",goodsTypeEntity);
         request.setAttribute("menu","goods_type");
         return "goods_type/modify_goodsType";
     }

     @RequestMapping("/add_goodsType")
     public String add_goodsType(HttpServletRequest request,GoodsTypeEntity goodsTypeEntity){
         int a = servie.add_GoodsTypeEntity(goodsTypeEntity);
         if(a>0) {
             return "redirect:/goodsType/query_goodsType";
         }else {
             return "forward:/error.jsp";
         }
     }

    @RequestMapping("/modify_goodsType")
     public String modify_goodsType(HttpServletRequest request,GoodsTypeEntity goodsTypeEntity){
         int a = servie.modify_GoodsTypeEntity(goodsTypeEntity);
         if(a>0) {
             return "redirect:/goodsType/query_goodsType";
         }else {
             return "forward:/error.jsp";
         }
     }

     @RequestMapping("/delete_goodsType")
     public String delete_goodsType(HttpServletRequest request,Integer id){
         int a = servie.delete_GoodsTypeEntity(id);
         if(a>0) {
             return "redirect:/goodsType/query_goodsType";
         }else {
             return "forward:/error.jsp";
         }
     }
}
